package com.zz.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.List;
import java.util.Set;

/**
 * @Author zhangbin
 * @Create 2023-02-14 9:51
 * @Description
 */
public class BiologicalApiUtil {

    // 获取合同数据
    public static JSONObject getContractData(String accessToken, String contractId) {
        return CrmApiUtil.getDataById(accessToken, "https://www.zohoapis.com.cn/crm/v3/Contract", contractId);
    }

    // 获取开发上量奖励数据
    public static JSONObject getIncentiveData(String accessToken, String incentiveId) {
        return CrmApiUtil.getDataById(accessToken, "https://www.zohoapis.com.cn/crm/v3/Incentive_Agreement", incentiveId);
    }

    // 查询合同配送商业公司
    public static List<JSONObject> getBusinessCompany(String accessToken, String contractId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Contract_Deliver_Company/search?criteria=(Contract_c:equals:" + contractId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 查询销售指标
    public static List<JSONObject> getSaleTarget(String accessToken, String contractId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Delivery_Plan/search?criteria=(Contract_c:equals:" + contractId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 查询合同开发指标
    public static List<JSONObject> getDevelopTarget(String accessToken, String contractId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/ContractDevelopmentIndex/search?criteria=(Contract_c:equals:" + contractId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 查询目标医院
    public static List<JSONObject> getTargetHospital(String accessToken, String targetId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/TargetHospital/search?criteria=(id:equals:" + targetId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 查询目标医院 批量
    public static List<JSONObject> getTargetHospitalBatch(String accessToken, Set<String> idList) {
        String url = "https://www.zohoapis.com.cn/crm/v3/TargetHospital/search?criteria=(id:in:" + getSetStr(idList) + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }


    // 查询合同目标医院
    public static List<JSONObject> getContractTargetHospital(String accessToken, String contractId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Contract_Target_Hospital/search?criteria=(Contract_c:equals:" + contractId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 查询开发上量奖励目标医院
    public static List<JSONObject> getIncentiveTargetHospital(String accessToken, String incentiveId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Incentive_Agreement_TargetHospital/search?criteria=(Incentive_Agreement_c.id:equals:" + incentiveId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 查询目标医院开发计划
    public static List<JSONObject> getHospitalDevelop(String accessToken, String contractId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Target_Hospital_Plan/search?criteria=(Contract_c:equals:" + contractId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 协议收款人信息
    public static List<JSONObject> getPayerMessage(String accessToken, String contractId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/ContractAccount/search?criteria=(Contract_c:equals:" + contractId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 推广产品（包装包材）
    public static List<JSONObject> getPackingMaterial(String accessToken, String packageId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/ProductWrapper/search?criteria=(id:equals:" + packageId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 推广产品（包装包材），按照产品查找
    public static List<JSONObject> getPackingMaterialByProduct(String accessToken, String packageId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/ProductWrapper/search?criteria=(id:equals:" + packageId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 产品
    public static List<JSONObject> getProduct(String accessToken, String productId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Products/search?criteria=(id:equals:" + productId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 产品流向每月汇总
    public static List<JSONObject> getProductTotal(String accessToken, String hospitalId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Product_Flow_Sum_c/search?criteria=(Target_HospitalF_c.id:equals:" + hospitalId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 产品流向每月汇总 批量查询
    public static List<JSONObject> getProductTotalBatch(String accessToken, Set<String> idList) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Product_Flow_Sum_c/search?criteria=(Target_HospitalF_c.id:in:" + getSetStr(idList) + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 配送产品
    public static List<JSONObject> getDistributionProduct(String accessToken, String contractId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Customer_Count/search?criteria=(Contract_c.id:equals:" + contractId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 基础档案
    public static List<JSONObject> getBasicFile(String accessToken, String id) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Accounts/search?criteria=(id:equals:" + id + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 用户信息
    public static List<JSONObject> getUserInfo(String accessToken, String id) {
        String url = "https://www.zohoapis.com.cn/crm/v3/User_Profile/search?criteria=(id:equals:" + id + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 用户信息 根据其 【用户 ID】查询
    public static List<JSONObject> getUserInfoSearch(String accessToken, String id) {
        String url = "https://www.zohoapis.com.cn/crm/v3/User_Profile/search?criteria=(User_ID:equals:" + id + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 联系人
    public static List<JSONObject> getContactPerson(String accessToken, String id) {
        String url = "https://www.zohoapis.com.cn/crm/v3/Contacts/search?criteria=(id:equals:" + id + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 合同目标医院配送商业
    public static List<JSONObject> getTargetHospitalBusiness(String accessToken, String id) {
        String url = "https://www.zohoapis.com.cn/crm/v3/ContractHospitalPointDetail/search?criteria=(ContractTargetHospital_c.id:equals:" + id + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 合同目标医院配送商业 批量
    public static List<JSONObject> getTargetHospitalBusinessBatch(String accessToken, Set<String> idList) {
        String url = "https://www.zohoapis.com.cn/crm/v3/ContractHospitalPointDetail/search?criteria=(ContractTargetHospital_c.id:in:" + getSetStr(idList) + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 高开返款税率表主政策
    public static List<JSONObject> getTHighTax(String accessToken, String isIsProvinceRate, String Product_Wrapper_c) {
        String url = "https://www.zohoapis.com.cn/crm/v3/HighReturnMainTaxRate/search?criteria=(" +
                "(IsProvinceRate_c:equals:" + isIsProvinceRate + ")and" +
                "(Validation_Status_c:equals:有效)and" +
                "(Product_Wrapper_c.name:equals:" + Product_Wrapper_c + ")" +
                ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 价格手册
    public static List<JSONObject> getPriceManual(String accessToken, String agent_product_package_c_name, String agent_Province_c) {
        String url = "https://www.zohoapis.com.cn/crm/v3/PriceManual/search?criteria=(" +
                "(Wrapper_c.name:equals:" + agent_product_package_c_name + ")and" +
                "(Province_c:equals:" + agent_Province_c + ")" +
                ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 服务商准入
    public static List<JSONObject> getServiceAccess(String accessToken, String id) {

        String url = "https://www.zohoapis.com.cn/crm/v3/ContractServiceProvider/search?criteria=(Contract_c.id:equals:" + id + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 获取set集合的字符串
    private static String getSetStr(Set<String> idList) {
        return idList.toString().substring(1, idList.toString().length() - 1).replaceAll(" ", "");
    }

    // 查询合同相关的目标医院销售指标
    public static List<JSONObject> getSaleTargetByContract(String accessToken, String id) {
        String url = "https://www.zohoapis.com.cn/crm/v3/TargetHospitalIndicatorList/search?criteria=(Contract_c.id:equals:" + id + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 根据基础档案 查询目标医院
    public static List<JSONObject> getSaleTargetByBasic(String accessToken, String id) {
        String url = "https://www.zohoapis.com.cn/crm/v3/TargetHospital/search?criteria=(Agent_c.id:equals:" + id + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 根据目标医院查询目标医院销售指标
    public static List<JSONObject> getSaleTargetSaleByBasic(String accessToken, String targetId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/TargetHospitalIndicatorList/search?criteria=((Target_HospitalF_c.id:equals:" + targetId + ")and(Template:equals:true))";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 根据目标医院查询目标医院销售指标 批量
    public static List<JSONObject> getSaleTargetSaleByBasicBatch(String accessToken, Set<String> idList) {
        String url = "https://www.zohoapis.com.cn/crm/v3/TargetHospitalIndicatorList/search?criteria=(Target_HospitalF_c.id:in:" + getSetStr(idList) + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }

    // 根据目标医院查询目标医院销售指标变更申请
    public static List<JSONObject> getSaleTargetSaleChangeByBasic(String accessToken, String targetId) {
        String url = "https://www.zohoapis.com.cn/crm/v3/TargetHospitalSaleTargetChange/search?criteria=(Target_Hospital_c.id:equals:" + targetId + ")";
        return CrmApiUtil.getModuleDataBySearch(accessToken, url);
    }


}
